package com.ljx.funchat.websocket;

import io.netty.channel.Channel;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;


public class NettyUtil {

    public static AttributeKey<String> IP = AttributeKey.valueOf("ip");
    public static AttributeKey<String> TOKEN = AttributeKey.valueOf("token");
    public static AttributeKey<String> UID = AttributeKey.valueOf("UID");

    public static <T> void setAttr(Channel channel, AttributeKey<T> key, T data){
        Attribute<T> attr = channel.attr(key);
        attr.set(data);
    }

    public static <T> T getAttr(Channel channel, AttributeKey<T> key){
        Attribute<T> attr = channel.attr(key);
        return attr.get();
    }

}
